{$contents}

{literal}
<div style="text-align:left; padding:10px;">
<h2>Source</h2>

<pre class="code">
&lt;?php

$this-&gt;view-&gt;addPartitioner('contents', 'DomFg/Source/ImageGrid.html');

$post = DomFgPost::getInstance('mySearchName');
$query = ImageGridImage::query()-&gt;orderBy('t.`order`');

if( $_GET['deleteImage'] && $image = ImageGridImage::load($_GET['deleteImage']) ) {
	$image-&gt;delete();
}

if( $post-&gt;addImage ) {
	$image = new ImageGridImage();
	$image-&gt;title = $post-&gt;title;
	$image-&gt;icon-&gt;addUploaded( $post-&gt;image[0], $post-&gt;image[1] );
	$image-&gt;save();
}

if( $post-&gt;save ) {
	foreach( $query-&gt;commit() as $i =&gt; $image ) {
		$image-&gt;order = $post-&gt;images['order'][$i];
		$image-&gt;save();
	}
}

function getIcon( &$row ) {
	return $row-&gt;icon-&gt;toHtml();
}

function makeBold( $value ) {
	return '&lt;b&gt;' . $value . '&lt;/b&gt;';
}

$grid = array(
	'title' =&gt; 'ImageGrid',
	'style' =&gt; 'width: 800px',
	'action' =&gt; $this-&gt;getUrl('imageGrid/'),
	'layout' =&gt; 'table',
	'items' =&gt; array(
		array(
			'colspan' =&gt; 2,
			'type' =&gt; 'info',
			'message' =&gt; 'ImageGrid',
			'description' =&gt; 'Notice that image grid also allows reordering images. You can drag images to reorder them!.&lt;br&gt; If you delete all images then 20 images will be automatically added to this gallery.'
		),
		array(
			'type' =&gt; 'fieldSet',
			'layout' =&gt; 'table',
			'colspan'  =&gt; 2,
			'title' =&gt; 'Add new image',
			'items' =&gt; array(
				array(
					'title' =&gt; 'Title',
					'type' =&gt; 'textField',	
					'name' =&gt; 'title',
				),
				array(
					'title' =&gt; 'Image file',
					'type' =&gt; 'file',	
					'name' =&gt; 'image',
				),
				array('type'=&gt;'value'),
				array(
					'type' =&gt; 'button',
					'title' =&gt; 'Add',
					'name' =&gt; 'addImage',
				),
			),
		),
		array(
			'type' =&gt; 'imageGrid',
			'id' =&gt; 'images',
			'name' =&gt; 'images',
			'colspan' =&gt; 2,
			'ordering' =&gt; true,
			'link' =&gt; $this-&gt;getUrl('simpleGrid'),
			'source' =&gt; new DomArDataSource( $query, 99999),
			'fields' =&gt; array(
				array('handler'=&gt;'getIcon'),
				array('key' =&gt; 'title','handler'=&gt;'makeBold'),
				array('type' =&gt; 'gridButton','value' =&gt; 'Delete','link' =&gt; $this-&gt;getUrl('imageGrid/&deleteImage='),'confirmMessage' =&gt; 'Are you sure?',),
			),
		),
	),
	'buttons' =&gt; array(
		array(
			'title' =&gt; 'Save',
			'name' =&gt; 'save',
		),
	),
);


$this->view->contents = DomFg::render( $grid );
?&gt;
</pre>
</div>
{/literal}